package edu.gdin.ecommerce.dao;

import java.util.Date;

import org.springframework.stereotype.Repository;

import edu.gdin.ecommerce.model.Customer;
import edu.gdin.ecommerce.util.Pager;

@Repository("customerDAO")
public class CustomerDAO extends BaseDAO {
	public Pager queryCustomer(Customer customer, String from, String to, Integer cPage){
		String hql = "from Customer c where 1=1";
		hql += customer.getName() == null || customer.getName().trim().equals("") ? "" : " and c.name like '%" + customer.getName() + "%'";
		hql += customer.getMobile() == null || customer.getName().trim().equals("") ? "" : " and c.mobile like '%"+customer.getMobile()+ "%'";
		hql += customer.getCertificateNo() == null || customer.getCertificateNo().trim().equals("") ? "" : " and c.certificateNo like '%"+customer.getCertificateNo()+ "%'";
		hql += from == null || from.trim().equals("")? "" : " and c.createTime >= '"+ from +" 00:00:00'";
		hql += to == null || to.trim().equals("")? "" : " and c.createTime <= '" + to + " 23:59:59'";
		
		return this.getPage(hql, cPage);
 	}
}
